chrome.extension.sendMessage({}, function(response) {
	var readyStateCheckInterval = setInterval(function() {
	if (document.readyState === "complete") {
		clearInterval(readyStateCheckInterval);

		// ----------------------------------------------------------
		// This part of the script triggers when page is done loading
		console.log("Hello. This message was sent from scripts/inject.js");
		// ----------------------------------------------------------

		{	// from: http://orip.org/2009/05/jquery-ui-scoped-themes-and-dialog.html
			// Wraps the dialog in a div with the scoping class on
			// dialog open, removes the scoping class on dialog close
			$.fn.dialogScopingWorkaround = function(scopingClass) {
			  this.bind('dialogopen', function(event, ui) {
				$(this).parents(".ui-dialog").wrap(
				  '<div class="dialogScopingWrapper '
				  + scopingClass
				  + '"></div>'
				);
			  });
			  this.bind('dialogclose', function(event, ui) {
				var wrapper = $(this).parents(".dialogScopingWrapper");
				wrapper.replaceWith(wrapper.children());
			  });
			  return this;
			};
		}


		// gather all links
		var $pidLinks = $('a[href]');
		var $imgLinks = $pidLinks.filter(function(){
		        return this.href.match(/\.jpg|\.jpeg|\.png|\.gif/i);
		    });


		// create a popup
		var uniqueid = 'id' + (new Date()).getTime();
		var dlogelem = $(document.body).append('<div class="dlchromeext" id="'+uniqueid+'" > test </div>');
		setTimeout(function() {
			var divEl = $( "#"+uniqueid );
			debugger
			if (divEl) {
				divEl.dialogScopingWorkaround("dlchromeext").dialog( {
					title: "Dialog Title",
					resizable: true,
					position: { my: "right top", at: "right top", of: window },
					create: function( event, ui ) {

					}
				});
			}
		}, 10);
	}
	}, 10);
});